package biz.ezcom.spring.ioc.editor;

import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DatePropertyEditor extends PropertyEditorSupport {
	private String format;
	public void setFormat(String format) {
		this.format = format;
	}

	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		try {
			Date date = new SimpleDateFormat(format).parse(text);
			this.setValue(date);
		} catch (ParseException e) {
			e.printStackTrace();
			throw new IllegalArgumentException("时间转换异常");
		}
	}
	
}
